'use strict';

import Base from './base.js';

export default class extends Base {
    /**
     * index action
     * @return {Promise} []
     */
    init(http) {
        super.init(http);
        let WorkSerive = think.service('wealactive', 'wealactive');
        this.WorkSerive = new WorkSerive();
    }
    async addAction() {
        let self = this;
        let allParams = self.post();
        let Work = await self.WorkSerive.addWork(allParams)
        if (typeof Work !== 'number') {
            return self.fail(Work);
        } else {
            return self.success(Work);
        }
    }

    async getAction() {
        let self = this;
        let allParams = self.post() || {};
        allParams['orderBy'] = this.get('orderBy');
        allParams['work_id'] = this.get('work_id');
        let Work = await self.WorkSerive.getWork(allParams);

        if (typeof Work !== 'number') {
            return self.success(Work);
        } else {
            return self.fail(Work);
        }
    }

    async pollAction() {
        let self = this;
        let allParams = self.post();
        let Work = await self.WorkSerive.pollAdd(allParams);
        if (typeof Work === 'number') {
            return self.fail(Work);
        } else {
            return self.success(Work);
        }
    }
}
